<?php
set_time_limit(0);
header("Content-type: text/html; charset=utf-8");


/**
* 采集程序类
* @author  shooting
* @version 1.0.0
*/
class spider
{

/**
* 程序运行时间
*
* @var float
*/
var $runtime = 0;
/**
* 被采集页面编码
*
* @var string
*/
var $charset = 'UTF-8';
var $strtoupper;
/**
* 采集地址
*
* @var integer
*/
var $kuiurl;
var $kuibody;
var $content;
/**
* 页面引用地址
*
* @var string
*/
var $httpreferer;

/**
* 正在处理的文件内容
*
* @var string
*/
var $httpContent;
/**
* 获取内容
*
* @param string $content
*/
function getContent()
{
  	$url = $this->kuiurl;
	$snoopy = new Snoopy;


	$snoopy->fetch(str_replace(" ","",$url)); 
	$kui_nerrongsoso = $snoopy->results; 
   $content = iconv('gb2312','utf-8',$kui_nerrongsoso);
	$content = $kui_nerrongsoso;

  	$this->content=$content;
}
/**
* 获取内容
*
* @param string getbody
*/
function getbody()
{
	$and=$this->kuibody[0];
	$end=$this->kuibody[1];
	$list_html=$this->content;
	$ary=split($and,$list_html);
	$ary=split($end,$ary[1]); 
	$list_content = $ary[0];

	return $list_content;

}

/**
* 采集标题
* @param string $list_title
*/
function gettitle($and,$i,$yes='0')
{

	$list_content=$this->getbody();
	preg_match_all($and, $list_content, $list_title);

	if($yes=='1'){
		foreach($list_title[$i] as $id=>$t){
			$regex[url] = "((http|https|ftp|telnet|news):\/\/)?([a-z0-9_\-\/\.]+\.[][a-z0-9:;&#@=_~%\?\/\.\,\+\-]+)";
			$list_title[$i][$id] = eregi_replace("$regex[url]","", $list_title[$i][$id]); 
			$list_title[$i][$id] = preg_replace("'<div[^>]*?hidden.*?</div>'si","", $list_title[$i][$id]);
			$list_title[$i][$id] = eregi_replace("<[^br][^<>]*>","", $list_title[$i][$id]); 

		}
		}

		if($i==='yes'){

				return $list_title;
		}else{
			return $list_title[$i];

		}
}


}


?>


